<%@page import="com.system.dao.RoleDao"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../common.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'userEdit.jsp' starting page</title>
  </head>
  
  <style type="text/css">

	.gray{
		color:Gray;
	}
	
  </style> 
  
  <script type="text/javascript">
    
    	var drugId = "${param.id}";
    	var value = "${param.value}";
    	var drug_min;
    	$().ready(function(){
    		if(value == '0'){
    			$("#min_num").attr("name","drugstore_min");
    		}else{
    			$("#min_num").attr("name","storeroom_min");
    		}
			if(drugId != "")
			{
				ajax.remoteCall("com.system.dao.DrugDao:findDrug",[drugId,value],function(reply){
					drug_min = reply.getResult()["drug_min"];
					doStyle(reply.getResult()["drug_min"]);
					Form.bindForm("winForm",reply.getResult());
				});
			}
    	});
    	
    	function doStyle(min) {
    		$("#min_num").addClass("gray")//添加灰色字体样式
    		.val(min)//添加文字
    		.bind({
    			//绑定以下两个事件
    			//①单击事件（如果文本框中的文字为输入查询关键字，则给文本框置为空，且移除灰色字体样式）
    			"focus": 
    			function () {
    				if ($(this).val() == min){
    					$(this).val("").removeClass("gray");
    				}
    			},
    			//②失去焦点事件（如果文本框没有输入内容，则为其添加请输入关键字 的提示信息，且添加灰色字体样式）
    			"blur": 
    			function () {
    				if($(this).val() == ""){
    					$(this).val(min).addClass("gray");
    				}
    			}
    		});
    	}
    	
    	function doSave(){
    		
    		if(doCheck()){
    			var map = Form.formToBean("winForm");
        		map.id = drugId;
        		ajax.remoteCall("com.system.dao.DrugDao:update",[map],function(reply){
        			var result = reply.getResult();
        			alert(result.value);
        			if(result.type == "success"){
        				var dlg = Dialog.getInstance("view");
        	    		dlg.getParam("window").mygrid.reload();
        	    		dlg.close();
        			};
        		});
    		};
    	}
    	
    	function doCheck(){
    		//var min_num = parseInt($("#min_num").val());
    		//var drugnum = parseInt($("#drugnum").val());
    		
    		var regExp = /^[0-9]*[1-9][0-9]*$/;
    		var min_num = $.trim($("#min_num").val());
    		
   			if((!regExp.test(min_num))){
   				if(min_num != 0 ){
	   				alert("请输入正整数");
	    			return false;
   				}
   			}
    		if($("#is_own").val() == 1){
	   			if(!confirm("收费方式为  公费  预警库存为  "+ min_num +" \n\n\t确认提交吗？")){
	   				return false;
	   			}
    		}else{
    			if(!confirm("收费方式为  自费  预警库存为  "+ min_num +" \n\n\t确认提交吗？")){
	   				return false;
	   			}
    		}
    		return true;
    	}
    	
    </script>
  
  <body>
   <form id="winForm" name="winForm">
   		<input name="id" type="hidden" value="${param.id}">
   		<input name="value" type="hidden" value="${param.value}">
  		<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
	  		<tr>
				<td valign="top" align="left">	
					<div style="padding:10px;">
						<table>
							<tr height="40px" valign="bottom">
								<td width="250" valign="middle" align="right" height="30">
									药品：<input type="text" name="name" id="name" class="textbox" readonly="readonly" style="width:160;color: blue;"/>
								</td>
								<td  width="250" valign="middle" align="right" height="30">
									规格：<input type="text" name="spec" id="spec" class="textbox" readonly="readonly" style="color: blue;"/>
								</td>
							</tr>
							<tr height="40px" valign="bottom">
								<td width="250" valign="middle" align="right" height="30">
									厂家：<input type="text" name="vender" id="vender" class="textbox" readonly="readonly" style="width:160;color: blue;"/>
								</td>
								<td  width="250" valign="middle" align="right" height="30">
									库存数：<input type="text" name="drug_num" id="drug_num" class="textbox" readonly="readonly" style="color: blue;"/>
								</td>
							</tr>
							<tr height="40px" valign="bottom">
								<td  width="250" valign="middle" align="right" height="30">
									<font color="#FF0000">*</font>收费方式：<select style="width:160;" id="is_own" name="is_own">
											<option value="0">自费</option>
											<option value="1">公费</option>
										  </select>
								</td>
								<td  width="250" valign="middle" align="right" height="30">
									<font color="#FF0000">*</font>预警存量：<input type="text" name="" id="min_num" class="textbox"/>
								</td>
							</tr>
							<tr height="25px" valign="bottom">
								<td colspan="2">
									<img src="${path}/images/tip.png" border="0" width="20px" height="15px" />
									<font color="green" style="font-size: 11px">温馨提示：请注意收费方式以及预警存量！</font>
								</td>
							</tr>
						</table>
					</div>
				</td>
			</tr>
  		</table>
	</form>
  </body>
</html>
